package com.experiment04;

import com.experiment04.entity.Student;
import com.experiment04.serviceimpl.StudentServiceImpl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map;
import static com.experiment04.service.StudentService.s1;

public class Test {
    public static void main(String[] args) {
        //addStudent();
        //listStudentsByYear(2021);
        //listStudentsNames(2021, Student.Sex.MALE);
        //listStudentsByYearSortedById(2021);
        //listStudentsMapBySex();
        //listStudentsByYearMapById(2021);
        removeStudent(1);
    }
     public static void addStudent(){

        List<Student> students = s1.addStudent(new Student(7,"肥波",Student.Sex.MALE,2021));
        for(Student s:students){
            System.out.println("id:" + s.getId());
            System.out.println("name:" + s.getName());
            System.out.println("sex:" + s.getSex());
            System.out.println("year:" + s.getYear());
        }


     }
     public static void listStudentsByYear(int year){

        List<Student> students = s1.listStudentsByYear(year);
         for(Student s:students){
             System.out.println("id:" + s.getId());
             System.out.println("name:" + s.getName());
             System.out.println("sex:" + s.getSex());
             System.out.println("year:" + s.getYear());
         }

     }
     public static void listStudentsNames(int year, Student.Sex sex) {

         List<String> students = s1.listStudentsNames(year, sex);
         for (String s : students) {
             System.out.println(s);
         }

     }
     public static void listStudentsByYearSortedById(int year){
        List<Student> students = s1.listStudentsByYearSortedById(year);
         for(Student s:students){
             System.out.println("id:" + s.getId());
             System.out.println("name:" + s.getName());
             System.out.println("sex:" + s.getSex());
             System.out.println("year:" + s.getYear());
         }

     }
     public static void  listStudentsMapBySex(){
         Map<Student.Sex,List<Student>> map = s1.listStudentsMapBySex();
         for(Map.Entry<Student.Sex,List<Student>> entry : map.entrySet()) {
             System.out.println(entry.getKey());
             for(Student student : entry.getValue()) {
                 System.out.println(student.getId());
                 System.out.println(student.getSex());
                 System.out.println(student.getName());
                 System.out.println(student.getYear());
                 }
             }

         }
         public static void listStudentsByYearMapById(int year){
        Map<Integer,Student> map = s1.listStudentsByYearMapById(year);
        for(Map.Entry<Integer,Student> entry : map.entrySet()) {


            System.out.println(entry.getValue().getId());
            System.out.println(entry.getValue().getName());
            System.out.println(entry.getValue().getSex());
            System.out.println(entry.getValue().getYear());


        }
         }
        public static void removeStudent(int id){
          boolean b1 = s1.removeStudent(id);
          if(!b1)
              System.out.println("true");
          else
              System.out.println("false");
         }
     }

